// pages/user_end/server_list/server_list.js
const app = getApp();
const request = require('../../../utils/request.js');
const url = require('../../../utils/url.js');
const cookie = require('../../../utils/cookie.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:0,
    type:2,
    service: [],
    nodata:1,
    keyword: '',
    page:1,
    noOrder:0,
    hasMoreData:true,
    list:[],
	category:[],
    token:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      id:options.id,
      type:options.type,
      keyword:options.key
    })
    this.getService();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
       token : wx.getStorageSync('token')
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.getService();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if (this.data.hasMoreData) {
      this.getService();
   } 
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  doSearch(){
    this.setData({
       page:1
    })
    this.getService();
  },
  getService() {
    var that = this;
	let cityName = wx.getStorageSync('cityName');
	console.log('cityName:'+cityName);
    let param = {
        key:that.data.keyword,
        service_category_id:that.data.id,
        type:that.data.type,
        page:that.data.page,
        token:that.data.token,
		cityName:cityName
    }
    wx.showNavigationBarLoading();  //在当前页面显示导航条加载动画
    request.request(url.servicelist, param, url.REQUEST_METHOD_GET).then((res) => {
          wx.hideNavigationBarLoading(); //在当前页面隐藏导航条加载动画
          // if (that.data.page == 1) {
          //     that.setData({
          //       list:[],
          //       noOrder:1,
          //     })
          // }
		  console.log('========');
		  console.log(res.data.data);
		   console.log('========');
          // var contentlistTem = that.data.list;
		   var contentlist = res.data.data.list;
           that.setData({
             list: contentlist,
			 category:res.data.data.Category,
             hasMoreData: false,
             noOrder:0,
           })
    })

  },
  gotoDetail(e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../server_info/server_info?id='+id,
    })
  },
  gotoHome(e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../index/index',
    })
  },
  goOrder(e){
    var id = e.currentTarget.dataset.id;
	var categoryname = e.currentTarget.dataset.categoryname;
    if(!this.data.token){
      wx.navigateTo({
        url:"../../authorization/authorization"
      })
      return false;
    }
	console.log('../payorder/payorder?id='+id+'&categoryname='+categoryname);
	
    wx.navigateTo({
      url:'../payorder/payorder?id='+id+'&categoryname='+categoryname
    })		
  },
  changekeyword(e){
    var keyword = e.detail.value;
    this.setData({
      keyword:keyword
    })
  }
})